export type IJudgeCallback = (val: any) => boolean;

export default class Judgement {
    private readonly judgement: IJudgeCallback;

    public constructor(judge: IJudgeCallback) {
        this.judgement = judge;
    }

    public judge(val: any) {
        return this.judgement(val);
    }


    public static isNumber(val: any) {
        return 'number' === (typeof val);
    }

    public static isInteger(val: any) {
        return this.isNumber(val) && val === (~~val);
    }

    public static isString(val: any) {
        return 'string' === (typeof val);
    }

    public static isBoolean(val: any) {
        return 'boolean' === (typeof val);
    }


    public static getNativeToStringValue(val: any) {
        return Object.prototype.toString.call(val);
    }

    public static isArray(val: any) {
        return val instanceof Array;
    }

    public static isObject(val: any) {
        return '[object Object]' === this.getNativeToStringValue(val);
    }

    public static isPlainObject(val: any) {
        return this.isObject(val) && 0 === Object.keys(val).length;
    }

    public static isNull(val: any) {
        return '[object Null]' === this.getNativeToStringValue(val);
    }

    public static isUndefined(val: any) {
        return '[object Undefined]' === this.getNativeToStringValue(val);
    }
}